home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15304 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: trib.apple.com!usenet
  2. From: Amir <Amir@bayarea.net>
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: H E L P
  5. Date: Thu, 04 Apr 1996 10:52:56 -0700
  6. Organization: Apple Computer, Inc., Cupertino, California
  7. Message-ID: <31640C78.56DE@bayarea.net>
  8. References: <N.040296.013047.18@DynamicPPP-185.HIP.CAM.ORG> <Pine.A32.3.91.960402135001.121719B-100000@green.weeg.uiowa.edu> <4js6jh$ndr@solutions.solon.com> <DpAx1J.4n9@iquest.net>
  9. NNTP-Posting-Host: 17.128.203.75
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (Macintosh; I; PPC)
  14.  
  15. Doug Miller wrote:
  16. > seebs@solutions.solon.com (Peter Seebach) wrote:
  17. > >In article <Pine.A32.3.91.960402135001.121719B-100000@green.weeg.uiowa.edu>,
  18. > >The Amorphous Mass  <robinson@blue.weeg.uiowa.edu> wrote:
  19. > >>On Tue, 2 Apr 1996 ramrod@cam.org wrote:
  20. > >
  21. > >>> The part that I am having a hard time with is the part that
  22. > >>> whatever number I enter for the age, I'm supposed to get the same number
  23. > >>> of happy faces, automatically.  For example If I say I am 45 years old,
  24. > >>> then the program should show 45 happy faces.
  25. > >
  26. > >>  You need a loop.  Look up the for, while, and do while loop constructs  in
  27. > >>your textbook.
  28. > >
  29. > >This is a bit strong.  You don't *need* a loop.  You just probably want one.
  30. > >
  31. > >Obviously, if you're assuming age, you would have no more than about 150 ifs
  32. > >to test, (assuming humans), and if you just want to do it for 45, it's even
  33. > >easier.
  34. > >
  35. > Obviously you didn't read what he wrote.  To satisfy the conditions of the task as he stated it,
  36. > he would need an infinite number of ifs ("whatever number I enter...").  I saw nothing in his
  37. > statement of the task that placed any limits of any sort on the number -- thus, he *does* need
  38. > a loop.
  39.  
  40. I agree with Peter, "whatever number I enter for the age", 
  41. means it is not infinite number but constrained by the max 
  42. age limit (150 seems quit safe).
  43.  
  44. 1. You can use loop.
  45. 2. you can use recursion, just one var in the stack, seems
  46.    safe for max 150 level deep:
  47.    
  48.    void printAge(int age)
  49.    {
  50.       if (age > 0)
  51.       {
  52.         printf("X");
  53.         printAge(age -1);
  54.       }
  55.       else
  56.         printf("\n");
  57.    }
  58.  
  59. 3. You can prepare a buffer of happy faces and just print 
  60.    it, e.g.:
  61.  
  62.    buf[150] = "\x01\x01\x01\x01 <--150 times --> \x01"
  63. ....
  64.    buf[age] = '\0';
  65.    printf("%s/n",buf);
  66.    buf[age] = '\1';
  67.    
  68.  
  69.  
  70.  
  71. --
  72. --        o o
  73. -----ooo---O---ooo-----------------------------------------
  74. --  Amir Deutel
  75. --
  76. --  Home: Amir@bayarea.net    http://www.bayarea.net/~amir/
  77. --  Work: Amir_Deutel@powertalk.apple.com
  78.